package com.elai.web.controller.baseconfig;

import com.elai.common.utils.poi.ExcelUtil;
import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.core.page.TableDataInfo;
import com.elai.common.enums.BusinessType;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.baseconfig.domain.BaseBlackListDO;
import com.elai.baseconfig.service.BaseBlackListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 黑名单Controller
 *
 * @author elai
 * @date 2021-07-18
 */
@RestController
@RequestMapping("/config/balcklist")
public class BaseBlackListController extends BaseController
{
    @Autowired
    private BaseBlackListService baseBlackListService;

    /**
     * 查询黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('config:balcklist:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseBlackListDO baseBlackList)
    {
        startPage();
        List<BaseBlackListDO> list = baseBlackListService.selectBaseBlackListList(baseBlackList);
        return getDataTable(list);
    }

    /**
     * 导出黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('config:balcklist:export')")
    @Log(title = "黑名单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BaseBlackListDO baseBlackList)
    {
        List<BaseBlackListDO> list = baseBlackListService.selectBaseBlackListList(baseBlackList);
        ExcelUtil<BaseBlackListDO> util = new ExcelUtil<BaseBlackListDO>(BaseBlackListDO.class);
        return util.exportExcel(list, "balcklist");
    }

    /**
     * 获取黑名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('config:balcklist:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(baseBlackListService.selectBaseBlackListById(id));
    }

    /**
     * 新增黑名单
     */
    @PreAuthorize("@ss.hasPermi('config:balcklist:add')")
    @Log(title = "黑名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseBlackListDO baseBlackList)
    {
        return toAjax(baseBlackListService.insertBaseBlackList(baseBlackList));
    }

    /**
     * 修改黑名单
     */
    @PreAuthorize("@ss.hasPermi('config:balcklist:edit')")
    @Log(title = "黑名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseBlackListDO baseBlackList)
    {
        return toAjax(baseBlackListService.updateBaseBlackList(baseBlackList));
    }

    /**
     * 删除黑名单
     */
    @PreAuthorize("@ss.hasPermi('config:balcklist:remove')")
    @Log(title = "黑名单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseBlackListService.deleteBaseBlackListByIds(ids));
    }
}
